<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!-- import CSS -->
		<script src="../../js/commonCss.js"></script>
		<title>添加/修改附加险</title>
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="pd10 border-bottom ft-14 h40">
				<a href="additionalRisks.html">
					<el-button type="text" icon="el-icon-arrow-left">添加/修改附加险</el-button>
				</a>
			</div>
			<div class="pd10">
				<el-form ref="form" :model="form" label-width="120px">
					<el-form-item label="产品名称：">
						<el-input type="text" v-model="form.iaTitle" style="width:300px;"></el-input>
					</el-form-item>
					<el-form-item label="保险公司：">
						<el-select v-model="form.iaComm" placeholder="请选择保险公司">
							<el-option :label="item.icTitle" :value="item.icId" v-for="item in companyArr" :key="item.icTitle"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="上传费率表：">
						<input type="file" id="imgFile" name="file" style="display:block;" accept=".xls, .xlsx" @change="handleFiles">
							<div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件</div>
						</el-upload>
					</el-form-item>
					<el-form-item>
						<el-button class="exitbtn" type="primary"  @click="downTemplate">下载模版</el-button>
					</el-form-item>
					<el-form-item>
						<el-button class="exitbtn" type="primary" @click="onSubmit" :loading="submit==0?true:false">保存</el-button>
						<el-button class="exitbtn" type="primary" @click="prev">返回</el-button>
					</el-form-item>
				</el-form>
			</div>
		</div>
	</body>
	<script src="/jeefast/elementui-lib/lib/vue.js"></script>
	<script src="/jeefast/elementui-lib/lib/index.js"></script>
	<script src="/jeefast/js/jquery-1.9.1.min.js"></script>
	<script src="/jeefast/js/axios.js"></script>
	<script src="/jeefast/js/data.js"></script>
	<script>
		var app = new Vue({
			el: "#app",
			mixins: [mix],
			data: function() {
				return {
					id: "",
					ImgApiMore: uploadPic,
					pic: "",
					companyArr: [],
					submit:1,
					formdata:"",
					form: {
						iaTitle: "",
						iaComm: "",
						rateUrl:""
					},
					// 上传
					fileList: [],
				}
			},
			methods: {
				prev(){
					window.history.go(-1);
				},
				/* 上传文件 */
				handleSuccess(res, file, fileList) {
					let that = this
					that.fileList=[]
					let params = {
						name:file.name
					}
					that.fileList.push(params)
					that.form.rateUrl = file.name
					that.$message({
						message: '上传成功！',
						type: 'success'
					});
				},
				handleRemove(file, fileList) {
					console.log(file, fileList);
				},
				// 下载模板
				downTemplate:function(){
					
				},
				//查询详情
				detail:function(){
					additionalDetail({id:this.id}).then(res=>{
						this.form = res.data.data;
					})
				},
				// 确定
				IsNull: function() {
					let flag = false;
					if (this.form.iaTitle == "") {
						this.$message.error('标题不能为空');
						return flag = true;
					}
					if (this.form.iaComm == "") {
						this.$message.error('保险公司不能为空');
						return flag = true;
					}
				},
				//获取excel文件
				handleFiles:function(){
					this.formdata.append('file', $("#imgFile")[0].files[0]);
					console.log("1122")
				},
				onSubmit: function() {
					let that = this;
					that.submit=0;
					if (that.IsNull()) {
						return;
					}
					// this.formdata = new FormData();
					this.formdata.append('iaTitle',that.form.iaTitle)
					if(this.id!=null){
						this.formdata.append('iaId',that.id)
					}
					this.formdata.append('iaComm',that.form.iaComm)
					console.log(this.formdata)
					$.ajax({
						type: "POST",
						// url: "http://localhost:7084/jeefast/irAdditional/additional/add?token=admin",
						// url: "http://122.14.213.160:7084/jeefast/irAdditional/additional/add?token=admin",
						url: "http://www.u-banker.net/jeefast/irAdditional/additional/add?token=admin",
						data: this.formdata,
						async: false,
						contentType: false,
						processData: false,
						success: function (res) {
							console.log(res)
							if(res.code==0){
								window.location = "/jeefast/modules/platform/additionalRisks.html";
							}
						},
						error: function (res) {
							that.submit=1;
							console.log(res.data)
						}
					})
					// window.location.href = 'additionalRisks.html'; //此处拼接内容
				},
			},
			created() {
				let that = this;
				//重新写一个表单上传的方法
				this.formdata = new FormData();
				this.id = getQueryString("id");
				//获取保险公司
				companyList({token:'admin',limit:10000}).then(res=>{
					that.companyArr = res.data.data;
					console.log(that.companyArr)
				})
				if (this.id == null) {
					console.log('==添加')
				} else {
					console.log('==编辑')
					that.detail();
				}
			},
		});
	</script>
</html>
